<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis ResultMap vs ResultType 深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            border-bottom: 1px solid #444;
        }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            font-size: 24px;
            margin-bottom: 20px;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                    MyBatis 映射艺术
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">
                    深入理解 ResultMap 与 ResultType 的设计哲学
                </p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-database mr-2"></i>数据映射
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-code mr-2"></i>最佳实践
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-lightbulb mr-2"></i>深度解析
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">在</span>MyBatis的世界里，数据映射是连接数据库与Java对象的桥梁。<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">ResultMap</code>和<code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">ResultType</code>作为两种核心的映射方式，各自承载着不同的设计理念和应用场景。理解它们的差异，是掌握MyBatis精髓的关键一步。
                </p>
            </div>
        </div>
    </section>

    <!-- Visual Comparison -->
    <section class="py-16 px-6 bg-gray-100">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-12 serif-font">
                <span class="gradient-text">核心对比</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- ResultMap Card -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="feature-icon bg-gradient-to-br from-purple-500 to-pink-500 text-white">
                        <i class="fas fa-sitemap"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">ResultMap</h3>
                    <p class="text-gray-600 mb-6">灵活强大的映射方案</p>
                    
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">支持复杂的映射关系，可自定义列名与属性名的对应</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">处理多表联合查询、嵌套查询等复杂场景</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">可重用配置，提高代码维护性</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">支持一对一、一对多等关联映射</span>
                        </li>
                    </ul>
                </div>

                <!-- ResultType Card -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="feature-icon bg-gradient-to-br from-blue-500 to-cyan-500 text-white">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">ResultType</h3>
                    <p class="text-gray-600 mb-6">简洁直接的映射方式</p>
                    
                    <ul class="space-y-3">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">直接指定结果类型，配置简单</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">适用于单表查询、简单字段映射</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">不支持灵活的映射规则</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times-circle text-red-500 mt-1 mr-3"></i>
                            <span class="text-gray-700">每次使用需重新定义，不可重用</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Relationship Diagram -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-12 serif-font">
                <span class="gradient-text">映射关系图解</span>
            </h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="mermaid">
                    graph TD
                        A[SQL查询结果集] --> B{映射方式选择}
                        B -->|ResultMap| C[灵活映射]
                        B -->|ResultType| D[简单映射]
                        
                        C --> E[自定义列名映射]
                        C --> F[关联关系映射]
                        C --> G[嵌套查询]
                        C --> H[可重用配置]
                        
                        D --> I[按顺序映射]
                        D --> J[单表查询]
                        D --> K[简单场景]
                        
                        E --> L[Java实体对象]
                        F --> L
                        G --> L
                        H --> L
                        I --> L
                        J --> L
                        K --> L
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style L fill:#9f9,stroke:#333,stroke-width:2px
                        style C fill:#bbf,stroke:#333,stroke-width:2px
                        style D fill:#fbf,stroke:#333,stroke-width:2px
                </div>
            </div>
        </div>
    </section>

    <!-- Code Example -->
    <section class="py-16 px-6 bg-gray-100">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-12 serif-font">
                <span class="gradient-text">实战代码示例</span>
            </h2>
            
            <div class="code-block">
                <div class="code-header">
                    <i class="fas fa-code mr-2"></i>MyBatis Mapper XML
                </div>
                <pre><code>&lt;!-- ResultMap 配置示例 --&gt;
&lt;resultMap id="userResultMap" type="com.ts.entity.User"&gt;
    &lt;!-- 主键映射 --&gt;
    &lt;id column="id" property="id"/&gt;
    
    &lt;!-- 普通字段映射 --&gt;
    &lt;result column="username" property="username"/&gt;
    &lt;result column="password" property="pw"/&gt;  &lt;!-- 列名与属性名不同 --&gt;
    
    &lt;!-- 一对多关联映射 --&gt;
    &lt;collection property="deptList" javaType="com.qf.entity.Dept"&gt;
        &lt;id column="dept_id" property="deptId"/&gt;
        &lt;result column="dept_name" property="deptName"/&gt;
    &lt;/collection&gt;
    
    &lt;!-- 一对一关联映射 --&gt;
    &lt;association property="emp" javaType="com.ts.entity.Emp"&gt;
        &lt;id column="emp_id" property="empId"/&gt;
        &lt;result column="emp_name" property="empName"/&gt;
    &lt;/association&gt; 
&lt;/resultMap&gt;

&lt;!-- 使用 ResultMap --&gt;
&lt;select id="findUserWithDetails" resultMap="userResultMap"&gt;
    SELECT u.*, d.*, e.*
    FROM t_user u
    LEFT JOIN t_dept d ON u.dept_id = d.id
    LEFT JOIN t_emp e ON u.emp_id = e.id
&lt;/select&gt;

&lt;!-- 使用 ResultType --&gt;
&lt;select id="findSimpleUser" resultType="com.ts.entity.User"&gt;
    SELECT * FROM t_user
&lt;/select&gt;</code></pre>
            </div>
        </div>
    </section>

    <!-- Best Practices -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-12 serif-font">
                <span class="gradient-text">最佳实践建议</span>
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-3xl mb-4 text-purple-600">
                        <i class="fas fa-lightbulb"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">场景选择</h3>
                    <p class="text-gray-600">简单查询使用 ResultType，复杂映射选择 ResultMap，根据实际需求灵活运用。</p>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-3xl mb-4 text-blue-600">
                        <i class="fas fa-recycle"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">重用原则</h3>
                    <p class="text-gray-600">将常